
export {
    uploadImg
}

import axios from "axios"

var uploadImg = {
    /**
 * markdown中插入图片
 * @param event 
 * @param insertImage 
 * @param files 
 */
    handleUploadImage: (event: any, insertImage: any, files: File[]) => {
        let formData: any = new FormData()
        formData.append('image', files[0])

        let imgToken = ''
        // 得到图床token
        axios.post("https://www.imgtp.com/api/token", {
            "email": "760303601@qq.com",
            "password": "Ww18775383672.",
            "refresh": 1
        }).then(res => {
            console.log(res);
            imgToken = res.data.token

            // 发送图床
            axios.post("https://www.imgtp.com/api/upload", formData, {
                headers: { 'Content-Type': 'multipart/form-data', "token": imgToken }
            }).then(res => {
                console.log('result', res);
                insertImage({
                    url: res.data.data.url
                })
            })

        })

    },

    uploadImgage: (files: File[]) => {
        let formData: any = new FormData()
        formData.append('image', files[0])

        let imgToken = ''
        // 得到图床token
        axios.post("https://www.imgtp.com/api/token", {
            "email": "760303601@qq.com",
            "password": "Ww18775383672.",
            "refresh": 1
        }).then(res => {
            console.log(res);
            imgToken = res.data.tokeny

            // 发送图床
            axios.post("https://www.imgtp.com/api/upload", formData, {
                headers: { 'Content-Type': 'multipart/form-data', "token": imgToken }
            }).then(res => {
                console.log('result', res);
                return res.data.data.url;
            })

        })
    }
}